/* 
 * Copyright (C) 2013, 2014 lex xiang
 *
 * file:	sys/main.c
 * history:	2013 Juy 5 created by lex xiang
 */

#include "uart.h"
#include "tty.h"
#include "version.h"
#include "shell.h"
#include "boot.h"
#include "s3c2440.h"
#include <stdio.h>

void Main(void)
{
	struct tty *tty;
	struct shell *sh;

	gpio_init();
	exc_init();
	cal_cpu_bus_clk();

	uart_init(0);

	REG32(0x56000080) = REG32(0x56000080) & ~(1 << 3);
	REG32(0x56000080) = REG32(0x56000080) & ~(1 << 13);

	show_version();
	printf_d("uart#0		[OK]\n");
	//auto_boot();

	if (!(tty = tty_alloc())) {	/* it is never be error! */
		printf_d("panic of file: %s, line: %d\n", __FILE__, __LINE__);
		while (1);
	}
	tty_init(tty, 
		 0,
		 tty_get_char, 
		 tty_put_char, 
		 tty_put_string, 
		 tty_printf);

	if (!(sh = shell_alloc())) {
		printf_d("panic of file: %s, line: %d\n", __FILE__, __LINE__);
		while (1);
	}
	shell_init(sh, tty);

	while (1) ;

	return;
}
